using System;
using System.IO;
using System.Reflection;
using SpecMaker.Core.Interfaces;

namespace SpecMaker.Core
{
    public class FileLocAssemblyLoader : IAssemblyTypeLoader
    {
        public Type[] Get(string assmlocation)
        {
            var assm = Assembly.LoadFile(assmlocation);
            var refassm =
            assm.GetReferencedAssemblies();
            foreach (var name in refassm)
            {
                var dir = Path.GetDirectoryName(assmlocation);
                try
                {
                 
                    
                    var assmfile = Assembly.LoadFile(dir +"\\" + name.Name + ".dll");
                   
                }catch(Exception)
                {
                    try
                    {
                        Assembly.Load(name);
                    }
                    catch(Exception ex)
                    {
                        throw new Exception(dir +"\\" + name.Name , ex);
                    }
                }
            }
              return assm  .GetTypes();
        }
    }
}